package com.sinog.core.util.log;

import ch.qos.logback.core.PropertyDefinerBase;
import lombok.extern.slf4j.Slf4j;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @desc 用于logback日志获取请求ip，在logback-**.xml文件中引用
 * @author lzq
 * @date 2020-05-08 10:13 上午
 */
@Slf4j
public class LogUtil extends PropertyDefinerBase {

    /**
     * 获取本地IP
     * @return String
     */
    @Override
    public String getPropertyValue() {
        String ip = null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch(UnknownHostException e) {
            log.error("获取ip异常{}",e.toString());
        }
        return ip;
    }
}